package ssi.cameraTest;

public class GeoTest {

    private static int EARTH_RADIUS_KM = 6371;
    public static int MILLION = 1000000;
    static double lat1 = 41.951035;
    static double lon1 = 12.519385;
    static double lat2 = 0.0;
    static double lon2 = 0.0;
    
	public static void main(String[] args) {
		double myBearing = bearing(lat1, lon1, lat2, lon2);
		System.out.println(myBearing);
	}

    public static double bearing(double lat1, double lon1, double lat2, double lon2) {
        double lat1Rad = Math.toRadians(lat1);
        double lat2Rad = Math.toRadians(lat2);
        double deltaLonRad = Math.toRadians(lon2 - lon1);

        double y = Math.sin(deltaLonRad) * Math.cos(lat2Rad);
        double x = Math.cos(lat1Rad) * Math.sin(lat2Rad) - Math.sin(lat1Rad) * Math.cos(lat2Rad)
                * Math.cos(deltaLonRad);
        return radToBearing(Math.atan2(y, x));
    }
    
    public static double radToBearing(double rad) {
        return (Math.toDegrees(rad) + 360) % 360;
    }
	
}
